home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wtek0693.zip / OOPALLEY.ZIP / COLLECT.CPP < prev    next >
C/C++ Source or Header  |  1993-04-27  |  2KB  |  90 lines

  1. #include "collect.h"
  2. #include "arrayob.h"
  3.  
  4. #define THIS    Collection
  5. #define BASE    Object
  6. DEFINE_CLASS(Collection,Object);
  7.  
  8. Object* Collection::add(const Object& ob)
  9. {
  10.     derivedClassResponsibility("add");
  11.     return (Object*)&ob;
  12. }
  13.  
  14. const Collection& Collection::addAll(const Collection& c)
  15. {
  16.     c.addContentsTo(*this);
  17.     return c;
  18. }
  19.  
  20. Collection& Collection::addContentsTo(Collection& ob) const
  21. {
  22.     derivedClassResponsibility("addContentsTo");
  23.     return ob;
  24. }
  25.  
  26. Object* Collection::remove(const Object& ob)
  27. {
  28.     derivedClassResponsibility("remove");
  29.     return (Object*)&ob;
  30. }
  31.  
  32. const Collection& Collection::removeAll(const Collection& c)
  33. {
  34.     DO(c,Object*,o) remove(*o); DONE
  35.     return c;
  36. }
  37.  
  38. void Collection::deepenShallowCopy() {}
  39.  
  40. Object*& Collection::at(int /*index*/) const
  41. {
  42.     static Object* dummy;
  43.     derivedClassResponsibility("at");
  44.     return dummy;
  45. }
  46.     
  47. bool Collection::includes(const Object& ob) const
  48. {
  49.     return occurrencesOf(ob) != 0;
  50. }
  51.  
  52. bool Collection::isEmpty() const { return size() == 0; }
  53.  
  54. unsigned Collection::occurrencesOf(const Object&) const
  55. {
  56.     derivedClassResponsibility("occurrencesOf"); return 0;
  57. }
  58.  
  59. ArrayOb Collection::asArrayOb() const
  60. {
  61.     ArrayOb a(size());
  62.     register Object** q = &(a.elem(0));
  63.     DO(*this,Object*,o) *q++ = o; DONE
  64.     return a;
  65. }
  66.  
  67.  
  68. Object* Collection::doNext(Iterator& /*pos*/) const
  69. {
  70.     derivedClassResponsibility("doNext"); return 0;
  71. }
  72.  
  73. void Collection::doReset(Iterator& pos) const
  74. {
  75.     pos.index = 0;
  76.     pos.ptr = (Object*)NULL;
  77.     pos.num = 0;
  78. }
  79.  
  80. Object* Collection::shallowCopy() const
  81. {
  82.     shouldNotImplement("shallowCopy"); return 0;
  83. }
  84.     
  85. unsigned Collection::size() const
  86. {
  87.     derivedClassResponsibility("size"); return 0;
  88. }
  89.  
  90.